import "package:ct_pa_majordomo/utils/request.dart";
import "package:dio/dio.dart";

enum BillStatus {
  dueIn,
  complete
}

extension EnumIndex on BillStatus {
  int get index => {
    BillStatus.dueIn: 1,
    BillStatus.complete: 2,
  }[this]!;
}

class BillApi {
  Future<Map> getBillList(queryParameters) async {
    Response response = await request.get(
      "apartment/bill/list",
      queryParameters: queryParameters,
    );
    return response.data ?? {};
  }

  Future<Map> removeBill(int billId) async {
    Response response = await request.delete(
      "apartment/bill/$billId",
    );
    return response.data ?? {};
  }

  /* 更新账单 */
  Future<Map> updateBill(data) async {
    Response response = await request.put(
      "apartment/bill",
      data: data,
    );
    return response.data ?? {};
  }

  Future<Map> batchAdd(data) async {
    Response response = await request.post(
      "apartment/bill/batchAdd",
      data: data,
    );
    return response.data ?? {};
  }

  Future<Map> batchRemove(String billIds) async {
    Response response = await request.delete(
      "apartment/bill/$billIds",
    );
    return response.data ?? {};
  }

  Future<Map> roomSummaryList(queryParameters) async {
    Response response = await request.get(
      "apartment/bill/room-summary-list",
      queryParameters: queryParameters,
    );
    return response.data ?? {};
  }
  
  /* 获取未提现金额 */
  Future<Map> getUnwithdrawAmount(int apartmentId) async {
    Response response = await request.get(
      "apartment/bill/unwithdraw-amount",
      queryParameters: { "apartmentId": apartmentId },
    );
    return response.data ?? {};
  }

  /* 获取未提现账单 */
  Future<Map> getUnwithdrawBillList(queryParameters) async {
    Response response = await request.get(
      "apartment/bill/unwithdraw-bills",
      queryParameters: queryParameters,
    );
    return response.data ?? {};
  }
}

BillApi billApi = BillApi();